package com.dev.service.service;

import java.util.List;

import com.dev.facade.entity.SyParam;
import com.dev.facade.service.SyParamService;
import org.springframework.stereotype.Component;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * @Description 系统操作业务实现类
 * @author Shiwen .Li
 * @date 2016年6月18日 下午9:53:45
 * @version V1.3.1
 */
@Component
public class SyParamServiceImpl extends BaseServiceImpl implements SyParamService {


	/**
	 * @param entity
	 * @return
	 */
	@Override
	public int save(SyParam entity) {
		logger.info("添加系统参数:{}",entity);
		return paramMapper.insertSelective(entity);
	}

	/**
	 * @param id
	 * @return
	 */
	@Override
	public int delete(Integer id) {
		logger.info("删除系统参数:{}",id);
		return paramMapper.deleteByPrimaryKey(id);
	}

	/**
	 * @param id
	 * @return
	 */
	@Override
	public SyParam getById(Integer id) {
		logger.info("查询系统参数:{}",id);
		return paramMapper.selectByPrimaryKey(id);
	}

	/**
	 * @param entity
	 * @return
	 */
	@Override
	public int update(SyParam entity) {
		logger.info("修改系统参数:{}",entity);
		return paramMapper.updateByPrimaryKeySelective(entity);
	}

	/**
	 * @param param
	 * @return
	 */
	@Override
	public List<SyParam> getlist(SyParam param) {
		logger.info("查询系统参数:{}",param);
		return paramMapper.getList(param);
	}


	@Override
	public int  insertTestTransaction() throws RuntimeException {
		int count=0;
		SyParam entity = new SyParam();
		for(int i=1;i<4;i++){
			entity.setName("产品名称"+i);
			entity.setValue("我要新世界！+i");
			entity.setRemark("你画我猜游戏+i");
			count+=this.paramMapper.insert(entity);
			if(i==3){
				try {
					logger.info("睡眠中");
					Thread.sleep(10000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				throw new RuntimeException();
			}
		}	
		return count;
	}

	@Override
	public Page<SyParam> getListByPage(SyParam params) {
		PageHelper.startPage(params.getNumber(), params.getLimit());
		return paramMapper.getListByPage(params);
	}

	@Override
	public int delete(String ids) {
		return paramMapper.delete(ids);
	}

}
